/*
 * @Author: wuqingchun
 * @Date: 2023-08-20 16:28:01
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-01-08 15:57:55
 */
#ifndef __FTPC_PI_H__
#define __FTPC_PI_H__

#define FTPC_PI_CODE_LEN 7
#define FTPC_PI_ADDR_PORT_LEN 31

typedef enum tagFTPCPiState
{
    FTPC_PI_STATE_INIT,
    FTPC_PI_STATE_CODE_1,
    FTPC_PI_STATE_CODE_2,
    FTPC_PI_STATE_CODE_3,
    FTPC_PI_STATE_SLINE_TEXT,
    FTPC_PI_STATE_MLINE_TEXT,
    FTPC_PI_STATE_MLINE_CR,
    FTPC_PI_STATE_MLINE_LF,
    FTPC_PI_STATE_MLINE_CODE_1,
    FTPC_PI_STATE_MLINE_CODE_2,
    FTPC_PI_STATE_MLINE_CODE_3,
    FTPC_PI_ADDR_PORT_BEGIN,
    FTPC_PI_ADDR_PORT_END,
    FTPC_PI_STATE_END_CR,          // '\r'
    FTPC_PI_STATE_END,             // '\n'

    FTPC_PI_STATE_ERROR,           // 错误状态
}FTPC_PI_STATE_E;

typedef struct tagFTPCPiContext
{
    FTPC_PI_STATE_E enState;
    char szCode[FTPC_PI_CODE_LEN + 1];
    int iReplyCode;
    char szAddrPort[FTPC_PI_ADDR_PORT_LEN + 1];
    unsigned int uiAddrPortLen;
}FTPC_PI_CONTEXT_S;

#define FTPC_PI_AGAIN    1
#define FTPC_PI_OK       0
#define FTPC_PI_FAILED  -1

void FTPC_pi_Init(FTPC_PI_CONTEXT_S *pstCtx);
int FTPC_pi_ParseReply(FTPC_PI_CONTEXT_S *pstCtx, const char *pcData, size_t ulDataLen);

#endif //__FTPC_PI_H__